Fix clearTimeout timer leaks in AbortController fetch patterns#36
Fix clearTimeout timer leaks in AbortController fetch patterns#36groupthinking merged 4 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
🚅 Deployed to the EventRelay-pr-36 environment in EventRelay
|
…eouts Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
…b-pr-33-another-one
There was a problem hiding this comment.
Pull request overview
This PR fixes timer leaks in the AbortController fetch patterns in two Next.js API routes. Previously, clearTimeout was called immediately after await fetch(...), meaning if the fetch threw an error (such as an AbortError triggered by the signal itself), the timeout would never be cleared. The fix wraps each fetch in a try/finally block so clearTimeout is guaranteed to run on all code paths. The package-lock.json changes reflect routine dependency tree cleanup (@swc/core, @cfworker/json-schema, and related peer packages removed as optional/unused, and fsevents dev flag update).
Changes:
apps/web/src/app/api/video/route.ts: Wrapped the 15-second backendfetchintry/finallyto always clear the abort timer.apps/web/src/app/api/transcribe/route.ts: Sametry/finallyfix for the 8-second backendfetch.package-lock.json: Removes entries for@swc/core,@cfworker/json-schema, and related packages that were optional peer dependencies, and updates thefseventsentry (removal of the"dev": trueflag — a commonnpm installartifact).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
apps/web/src/app/api/video/route.ts |
Wraps 15s backend fetch in try/finally to guarantee clearTimeout runs on abort/throw |
apps/web/src/app/api/transcribe/route.ts |
Wraps 8s backend fetch in try/finally to guarantee clearTimeout runs on abort/throw |
package-lock.json |
Removes unused optional peer packages (@swc/core, @cfworker/json-schema, etc.) and updates fsevents metadata |
clearTimeoutwas placed afterawait fetch(...)in both/api/videoand/api/transcriberoutes, meaning it never ran when the fetch threw (including the intentionalAbortErrorfrom the signal). This left timers pending in every error/abort path.Changes
apps/web/src/app/api/video/route.ts— Wrapped the 15s backend fetch intry/finallyso the timeout is always clearedapps/web/src/app/api/transcribe/route.ts— Same fix for the 8s YouTube backend transcript fetchAlso included in this branch (prior commits):
transcript_segmentsnow correctly readsresult.transcript?.segments?.lengthfor object-shaped transcripts, falling back toresult.transcript.lengthfor arraysENABLE_VERTEX_AIenv var now parsed as an explicit boolean ("1"/"true"/"yes") instead of raw truthiness, preventing"0"or"false"from triggering the slow Vertex AI metadata probe✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.